﻿using System.Collections.Generic;
using System.Linq;
using JetBrains.ReSharper.Psi.CSharp.Tree;
using Twins.Infrastructure;
using Twins.Interface;
using Twins.Interface.IHandler;
using Twins.Interface.IProcesser;

namespace Twins.Classes.Hanlder.HanlderStatement
{
    public class HanlderForIBlock : IHandler<IBlock>
    {
        public IEnumerable<ILineCode> DoFor(IBlock block)
        {
            var hashLineCodes = new List<ILineCode>();
            var processerCSharpStatement = IoC.Resolve<IProcesser>("ProcesserCSharpStatement"); 
            foreach (var lineCodes in block.Statements
                .Select(processerCSharpStatement.DoSomethingWith)
                .Where(lineCodes => lineCodes != null))
                hashLineCodes.AddRange(lineCodes);
            return hashLineCodes;
        }

        public IEnumerable<ILineCode> DoFor(object obj)
        {
            return DoFor((IBlock) obj);
        }
    }
}